package com.moliku.insurance.common.util;

import java.security.MessageDigest;
/**
 * @Description: 梧桐车联--密文转换
 * @Date: 2021/3/22 14:13
 */
public class ValidateUtil {

    public static String encodeChannel(String s) {
        return encode(s + "wuzhou_95f77bf0c250");
    }

    private static String encode(String s) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] bytes = md.digest(s.getBytes("utf-8"));
            return toHex(bytes);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private static String toHex(byte[] bytes) {

        final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray();
        StringBuilder ret = new StringBuilder(bytes.length * 2);
        for (int i = 0; i < bytes.length; i++) {
            ret.append(HEX_DIGITS[(bytes[i] >> 4) & 0x0f]);
            ret.append(HEX_DIGITS[bytes[i] & 0x0f]);
        }
        return ret.toString();
    }

    public static void main(String[] args) {
        String str = "{\"policyNo\":\"65001001360201900000000079\"}";
        System.out.println(encodeChannel(str));
    }

}











